//
//  STTabBar.m
//  OCVVeibo
//
//  Created by leergou on 16/7/20.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

#import "STTabBar.h"
#import <Masonry.h>

@interface STTabBar ()

// composeButton
@property (nonatomic,strong) UIButton *composeButton;

@end

@implementation STTabBar

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}

#pragma mark - 按钮点击事件
- (void)composeBtnClick:(UIButton *)sender{
    
    if (self.composeBtnClick) {
        self.composeBtnClick(sender);
    }
}

#pragma mark - layoutSubViews
- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    CGFloat width = self.frame.size.width * 0.2;
    __block NSInteger index = 0;
    
    // 重新布局 item
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if ([obj isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            CGRect tempFram = obj.frame;
            tempFram.origin.x = index * width;
            tempFram.size.width = width;
            obj.frame = tempFram;
            
            index++;
            if (index == 2) {
                index++;
            }
        }
    }];
}

#pragma mark - setupUI
- (void)setupUI{
    [self addSubview:self.composeButton];
    [self.composeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.centerY.mas_equalTo(self);
    }];
}

#pragma mark - lazy
- (UIButton *)composeButton{
    
    if (!_composeButton) {
        _composeButton = [[UIButton alloc]
                      initWithTitle:nil
                           bgNorImg:@"tabbar_compose_button"
                          bgHighImg:@"tabbar_compose_button_highlighted"
                     highlightedImg:@"tabbar_compose_icon_add_highlighted"
                          normalImg:@"tabbar_compose_icon_add" selectedImg:nil
                             target:self
                             action:@selector(composeBtnClick:)];
    }
    return _composeButton;
}


@end












